package cn.xxi.ai.application.dto;

import cn.xxi.ai.application.entity.MessageData;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Objects;

/**
 * SSE 推送的消息 DTO 视图类
 */
@Data
@AllArgsConstructor
public class SseChatMessage extends Message {

    private final Long messageId;

    private final Long conversationId;

    private final String content;

    @JsonTypeInfo(
            use = JsonTypeInfo.Id.SIMPLE_NAME,
            include = JsonTypeInfo.As.EXTERNAL_PROPERTY,
            property = "type"
            // defaultImpl 可根据需要补充
    )
    private final MessageData data;

    public SseChatMessage(cn.xxi.ai.application.entity.Message messageWithId) {
        this(
                messageWithId.getId(),
                Objects.nonNull(messageWithId.getConversation()) ? messageWithId.getConversation().getId() : null,
                messageWithId.getContent(),
                messageWithId.getData()
        );
    }
}
